package ru.spb.osll.myfit.fixtures.base;

import static org.junit.Assert.assertEquals;

import java.io.PrintWriter;

import org.junit.Test;

import ru.spb.osll.myfit.util.StringPrintWriter;
import fit.Fixture;
import fit.FixtureLoader;
import fit.Parse;

public class MyFitTableFixtureTest {
	private static final String SYSTEM_LINE_SEPARATOR = System
			.getProperty("line.separator");

	private static final String HTML = "<table border=\"1\" cellspacing=\"0\">\n"
			+ "<tr><td colspan=\"2\">dummy table</td>\n"
			+ "</tr>\n"
			+ "<tr class=\"error\"><td class=\"pass\">OK</td>\n"
			+ "<td class=\"fail\">ERROR <span class=\"fit_label\">"
			+ "expected</span><hr>OK <span class=\"fit_label\">actual</span></td>\n"
			+ "</tr>\n<tr><td>OUPS</td>\n"
			+ "<td>OK</td>\n"
			+ "</tr>\n</table>\n";

	@Test
	public void testTableFixture() throws Exception {
		Parse table = new Parse(OneLineFixtureUtilsTest
				.wiki2html("|dummy table|\n" + "|OK|ERROR|\n" + "|OUPS|OK|"));
		FixtureLoader.instance().addPackageToPath(
				"ru.spb.osll.myfit.fixtures.base");
		Fixture fixture = new Fixture();
		fixture.doTables(table);
		PrintWriter writer = new StringPrintWriter();
		table.print(writer);
		String actual = writer.toString();
		System.out.println(actual);

		String expected = HTML.replace("</td>\n", "</td>"
				+ SYSTEM_LINE_SEPARATOR);

		assertEquals(expected, actual);
	}
}
